package cn.easybuy.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import cn.easybuy.dao.BaseDao;
import cn.easybuy.dao.OrderDetailDao;
import cn.easybuy.entity.OrderDetail;

public class OrderDetailDaoImpl extends BaseDao implements OrderDetailDao {

	private Connection conn;
	private PreparedStatement pstmt;
	private ResultSet rs;
	
	@Override
	public int add(OrderDetail detail) {
		int result=0;
    	try {
    		
    		conn = super.getConnection();
    		
    		String sql=" insert into easybuy_order_detail(orderId,productId,quantity,cost) values(?,?,?,?) ";
    		
    		pstmt = conn.prepareStatement(sql);
    		
    		pstmt.setObject(1, detail.getOrderId());
    		pstmt.setObject(2, detail.getProductId());
    		pstmt.setObject(3, detail.getQuantity());
    		pstmt.setObject(4, detail.getCost());

    		result = pstmt.executeUpdate();
            
        } catch (Exception e) {
            e.printStackTrace();
        }finally{
        	super.closeAll(conn, pstmt, rs);
        }
    	return result;
	}

}
